﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using DALBase;
using MobileAPI.Entity.Model;
using System.Collections;
using System.Data;
using MobileAPI.Common;

namespace MobileAPI.DAL
{
    public class DALCustomerInfo:BaseDAL
    {
        public DBAccess db = DBConnection.CreateDB();


        public IList<ECustomerInfo> SearchCustomers(string CustomerName, string Instrument)
        {
            try
            {
                if(String.IsNullOrEmpty(CustomerName)&&String.IsNullOrEmpty(Instrument))
                {
                    return null;
                }
                if (String.IsNullOrEmpty(CustomerName))
                {
                    CustomerName = "'%'";
                }
                if (String.IsNullOrEmpty(CustomerName))
                {
                    Instrument = "'%'";
                }
                Hashtable hs = new Hashtable();
                hs.Add("客户名称", CustomerName);
                hs.Add("仪器型号", Instrument);
                DataTable dt = db.ExecuteStoredProcQuery("SP_CS_客户仪器", hs);
                IList<ECustomerInfo> list = null;
                if (dt != null && dt.Rows.Count > 0)
                {
                    list = new List<ECustomerInfo>();
                    ECustomerInfo es = null;
                    for (int i = 0; i < dt.Rows.Count; i++)
                    {
                        es = new ECustomerInfo();
                        es.CustomerName = dt.Rows[i]["客户名称"].TString();
                        es.Contact = dt.Rows[i]["联系人员"].TString();
                        es.Instrument = dt.Rows[i]["仪器型号"].TString();
                        es.InstrumentID = dt.Rows[i]["仪器序号"].TString();
                        es.InstrumentState = dt.Rows[i]["仪器状态"].TString();
                        es.Phone = dt.Rows[i]["联系电话"].TString();
                        es.RoomName= dt.Rows[i]["科室名称"].TString();
                        es.Area=dt.Rows[i]["装机区域"].TString();
                        list.Add(es);
                    }
                    return list;
                }
                return null;
            }
            catch (Exception e)
            {
                base.WriteLog(e.Message);
                throw e;
            }
        }
    }
}
